//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package objects;

import common.GlobalID;
import init.StaticData;
import java.util.Iterator;
import java.util.LinkedHashMap;

public class SellControl {
    private final LinkedHashMap<Integer, Integer> idToSafeCount = new LinkedHashMap();

    public SellControl() {
    }

    public Integer getSafeCount(Integer id) {
        Integer val = (Integer)this.idToSafeCount.get(id);
        return val != null?val:Integer.valueOf(0);
    }

    public void clearSafeCount() {
        this.idToSafeCount.clear();
    }

    public void addToSafeCount(Integer id) {
        Integer val = (Integer)this.idToSafeCount.get(id);
        if(val == null) {
            val = Integer.valueOf(0);
        }

        this.idToSafeCount.put(id, Integer.valueOf(val.intValue() + 1));
    }

    public void removeFromSafeCount(Integer id, Integer count) {
        Integer reserved = (Integer)this.idToSafeCount.get(id);
        if(reserved != null) {
            Integer result = Integer.valueOf(reserved.intValue() - count.intValue());
            if(result.intValue() < 0) {
                result = Integer.valueOf(0);
            }

            this.idToSafeCount.put(id, result);
        }

    }

    public void addToSafeCount(Integer id, Integer count) {
        Integer val = (Integer)this.idToSafeCount.get(id);
        if(val == null) {
            val = Integer.valueOf(0);
        }

        this.idToSafeCount.put(id, Integer.valueOf(val.intValue() + count.intValue()));
    }

    public int getSafeCountSilos() {
        Integer overall = Integer.valueOf(0);
        Iterator var3 = this.idToSafeCount.keySet().iterator();

        while(true) {
            Integer id;
            Integer count;
            do {
                if(!var3.hasNext()) {
                    return overall.intValue();
                }

                id = (Integer)var3.next();
                count = (Integer)this.idToSafeCount.get(id);
            } while(GlobalID.getClassID(id.intValue()) != 4 && GlobalID.getClassID(id.intValue()) != 61);

            overall = Integer.valueOf(overall.intValue() + count.intValue());
        }
    }

    public String safeCountToString() {
        Integer overall = Integer.valueOf(0);
        String val = "{ ";

        Integer id;
        Integer count;
        for(Iterator var4 = this.idToSafeCount.keySet().iterator(); var4.hasNext(); val = val + "\"" + StaticData.getGlobalName(id) + "\"=" + count + " ") {
            id = (Integer)var4.next();
            count = (Integer)this.idToSafeCount.get(id);
            overall = Integer.valueOf(overall.intValue() + count.intValue());
        }

        val = val + "}";
        return overall + ":" + val;
    }
}
